package cn.lutu.domain.schedule;

import cn.lutu.domain.service.ArticleService;
import cn.lutu.domain.service.InvoiceService;
import cn.lutu.domain.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Schedule {
    @Autowired
    private ArticleService articleService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private InvoiceService invoiceService;

    private Schedule(){
        log.info("创建计划任务组件对象");
    }


    @Scheduled(fixedRate = 300 * 1000)
    public void rebuildRedis(){
        log.info("重新加载文章列表缓存");
        articleService.rebuildRedis();
    }
    @Scheduled(fixedRate = 300 * 1000)
    public void rebuildSearch(){
        log.info("重新加载文章列表缓存");
        articleService.rebuildSearch();
    }

    @Scheduled(fixedRate = 300 * 1000)
    public void rebuildOrderRedis(){
        log.info("重新加载订单列表缓存");
        orderService.rebuildListCache();
    }

    @Scheduled(fixedRate = 300 * 1000)
    public void rebuildInvoiceRedis(){
        log.info("重新加载订单列表缓存");
        invoiceService.rebuildListCache();
    }
}
